﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using PropertyManagement.Core.Model;

namespace PropertyManagement.Core.DataAccess {
    public partial class InstrumentRecordDataAccess {
        public static InstrumentRecord GetLastRecord(int houseId, InstrumentType type) {
            var sql =
                "select top 1 * from dbo.InstrumentRecord where  HouseID = @houseid and InstrumentType = @instrumenttype order by CurrentDate desc ";

            var paramList = new[] {
                    new SqlParameter("houseid", houseId),
                     new SqlParameter("instrumenttype", type)
                };
            using (var iReader = SqlServerHelper.ExecuteReader(SqlServerHelper.ConnectionString, CommandType.Text, sql,
                                                            paramList)) {
                if (iReader.Read( )) {
                    return CreationInstrumentRecordByIReader(iReader);
                };
                return null;
            }
        } 
    }
}
